package com.test.system.admin.controller;

import com.github.pagehelper.PageInfo;
import com.test.system.admin.pojo.Bill;
import com.test.system.admin.pojo.Supplier;
import com.test.system.admin.pojo.TableData;
import com.test.system.admin.service.BillService;
import com.test.system.admin.service.SupplierService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @author 徒有琴
 */
@Controller
@RequestMapping("bill.html")
public class BillController {
    @Autowired
    private SupplierService supplierService;

    @Autowired
    private BillService billService;

    @RequestMapping
    public String bill(Model model) {
        //查询供应商列表
        List<Supplier> suppliers = supplierService.getSupplierList();
        model.addAttribute("suppliers", suppliers);//传给页面
        return "bill";
    }

    @RequestMapping(params = "act=table")
    @ResponseBody
    public TableData search(Bill bill,int page,int limit){
        if(limit<2||limit>20){

        }
        PageInfo<Bill>pageInfo=billService.getBillList(bill,page,limit);
        TableData tableData=new TableData();
        tableData.setCount(pageInfo.getTotal());
        tableData.setData(pageInfo.getList());
        return tableData;
    }
}
